package com.lzh.shijicloudstack.controller;

import com.lzh.shijicloudstack.common.R;
import com.lzh.shijicloudstack.common.ResultUtil;
import com.lzh.shijicloudstack.model.dto.cookbookCategory.AddCookbookCategoryDetailDto;
import com.lzh.shijicloudstack.model.dto.cookbookCategory.EditCookbookCategoryDetailDto;
import com.lzh.shijicloudstack.model.vo.cookbookCategory.CookbookCategoryDetailVO;
import com.lzh.shijicloudstack.service.CookbookCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 菜谱分类模块
 *
 * @author luzhiheng
 * @date 2025-02-17
 */
@Api(tags = "菜谱类别模块")
@RestController
@RequestMapping("/cookbook/category")
public class CookbookCategoryController {

    @Resource
    private CookbookCategoryService cookbookCategoryService;

    @ApiOperation(value = "菜谱分类列表查询")
    @PostMapping("/findList")
    public R<List<CookbookCategoryDetailVO>> findList() {
        return ResultUtil.success(cookbookCategoryService.findList());
    }

    @ApiOperation(value = "删除分类")
    @PostMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return ResultUtil.success(cookbookCategoryService.removeById(id));
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public R<Boolean> add(@RequestBody @Valid AddCookbookCategoryDetailDto dto) {
        return ResultUtil.success(cookbookCategoryService.add(dto));
    }

    @ApiOperation(value = "修改")
    @PostMapping("/edit")
    public R<Boolean> edit(@RequestBody @Valid EditCookbookCategoryDetailDto dto) {
        return ResultUtil.success(cookbookCategoryService.edit(dto));
    }

}
